#include "stdafx.h"
#include "wf_layerstogglelock.h"

#include "pf_graphic.h"



WF_LayersToggleLock::WF_LayersToggleLock(
    PF_Container& container,
    PF_GraphicView& graphicView)
        :PF_ActionInterface("Toggle Layer Visibility",
                    container, graphicView) {}


QAction* WF_LayersToggleLock::createGUIAction(LX_Define::ActionType /*type*/, QObject* /*parent*/) {
/*      QAction* action = new QAction(tr("Toggle Layer Lock"),
                                  tr("&Toggle Lock"),
                                  QKeySequence(), NULL); */
    QAction* action = new QAction(tr("Toggle Layer Lock"), NULL);
    //action->zetStatusTip(tr("Toggle Lock"));
    return action;
}

void WF_LayersToggleLock::trigger() {
    PF_DEBUG->print("toggle layer");
    if (graphic!=NULL) {
        PF_Layer* layer = graphic->getActiveLayer();
        if (layer!=NULL) {
            graphic->toggleLayerLock(layer);

            // deselect entities on locked layer:
            if (layer->isLocked()) {
                for (PF_Entity* e=container->firstEntity(); e!=NULL;
                        e=container->nextEntity()) {
                    if (e!=NULL && e->isVisible() && e->getLayer()==layer) {

                        if (graphicView!=NULL) {
                            graphicView->deleteEntity(e);
                        }

                        e->setSelected(false);

                        if (graphicView!=NULL) {
                            graphicView->drawEntity(e);
                        }
                    }
                }
            }
        }

    }
    finish();
}



void WF_LayersToggleLock::init(int status) {
    PF_ActionInterface::init(status);
    trigger();
}

// EOF
